//
//  CLproTableCell.m
//  I-want-go
//
//  Created by dllo on 15/10/29.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "CLproTableCell.h"
#import "CLsecondCollectionCell.h"
#import "CLdisgnerPic.h"
#import "CLtool.h"
#import "CLdisgner.h"
#import "CLscreen.h"
@interface CLproTableCell ()<UICollectionViewDataSource, UICollectionViewDelegate>

@end


@implementation CLproTableCell

- (void)dealloc {
    [_bigArr release];
    [_pushLabel release];
    [_phoneImage release];
    [_whiteView release];
    [_titleLabel release];
    [_funsLabel release];
    [_likeLabel release];
    [_classifyLabel release];
    [_picCollectionView release];
    [_leftView release];
    [_rightView release];
    [_addImage release];
    [_proArr release];
    [super dealloc];

}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}

- (void)createView {
    
    self.contentView.backgroundColor = [UIColor grayColor];
    
    self.whiteView = [[UILabel alloc] init];
    self.whiteView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.whiteView];
    [_whiteView release];
    
    self.titleLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.titleLabel];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.font = [UIFont systemFontOfSize:20];
    [_titleLabel release];
    
    self.funsLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.funsLabel];
    self.funsLabel.textAlignment = NSTextAlignmentCenter;
    self.funsLabel.textColor = [UIColor grayColor];
    [_funsLabel release];
    
    self.classifyLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.classifyLabel];
    self.classifyLabel.textAlignment = NSTextAlignmentCenter;
    self.classifyLabel.textColor = [UIColor grayColor];
    [_classifyLabel release];
    
    self.leftView = [[UIView alloc] init];
    self.leftView.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:self.leftView];
    [_leftView release];
    
    self.rightView = [[UIView alloc] init];
    self.rightView.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:self.rightView];
    [_rightView release];
    
    self.likeLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.likeLabel];
    self.likeLabel.textAlignment = NSTextAlignmentCenter;
    self.likeLabel.textColor = [UIColor grayColor];
    [_likeLabel release];
    
    self.addImage = [[UIImageView alloc] init];
    [self.contentView addSubview:self.addImage];
    [_addImage release];
    
    self.phoneImage = [[UIImageView alloc] init];
    [self.contentView addSubview:self.phoneImage];
    self.phoneImage.userInteractionEnabled = YES;
    [_phoneImage release];
    
    UITapGestureRecognizer *tag = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tagAction:)];
    [self.phoneImage addGestureRecognizer:tag];

    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake(100 * SWIDTH, 100 * SHEIGHT);
    self.picCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(12 * SWIDTH, 240 * SHEIGHT, 350 * SWIDTH, 120 * SHEIGHT) collectionViewLayout:flowLayout];
    self.picCollectionView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.picCollectionView];
    flowLayout.sectionInset = UIEdgeInsetsMake(10 * SWIDTH, 5 * SHEIGHT, 5 * SWIDTH, 10 * SHEIGHT);
    
    [_picCollectionView release];
    [self.picCollectionView registerClass:[CLsecondCollectionCell class] forCellWithReuseIdentifier:@"reuse"];
    
    self.pushLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.pushLabel];
    self.pushLabel.backgroundColor = [UIColor blackColor];
    self.pushLabel.textColor = [UIColor whiteColor];
    self.pushLabel.textAlignment = NSTextAlignmentCenter;
    [_pushLabel release];
    
    self.picCollectionView.dataSource = self;
    self.picCollectionView.delegate = self;
    
    
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    self.whiteView.frame = CGRectMake(8 * SWIDTH, 5  * SHEIGHT, 360 * SWIDTH, 360 * SHEIGHT);
    
    self.titleLabel.frame = CGRectMake(50 * SWIDTH, 110 * SHEIGHT, 275 * SWIDTH, 40 * SHEIGHT);
    
    self.funsLabel.frame = CGRectMake(50 * SWIDTH, 160 * SHEIGHT, 275 * SWIDTH, 20 * SHEIGHT);
    
    self.classifyLabel.frame = CGRectMake(50 * SWIDTH, 185 * SHEIGHT, 275 * SWIDTH, 20 * SHEIGHT);
    
    self.leftView.frame = CGRectMake(15 * SWIDTH, 220 * SHEIGHT, 100 * SWIDTH, 1 * SHEIGHT);
    
    self.rightView.frame = CGRectMake(260 * SWIDTH, 220 * SHEIGHT, 100 * SWIDTH, 1 * SHEIGHT);
    
    self.likeLabel.frame = CGRectMake(120 * SWIDTH, 210 * SHEIGHT, 130 * SWIDTH, 20 * SHEIGHT);
    
    self.phoneImage.frame= CGRectMake(150 * SWIDTH, 40 * SHEIGHT, 75 * SWIDTH, 70 * SHEIGHT);
    
    self.pushLabel.frame = CGRectMake(8 * SWIDTH, 5 * SHEIGHT, 360 * SWIDTH, 20 * SHEIGHT);
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.proArr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    CLsecondCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    
    CLdisgnerPic *dic = self.proArr[indexPath.row];
    
    [cell.picImage sd_setImageWithURL:[NSURL URLWithString:dic.image]];

    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    CLdisgnerPic *disgnerId = self.proArr[indexPath.row];
    [self.Delate pushWithId:disgnerId.productId];
}

- (void)tagAction:(UIGestureRecognizer *)tag {
    CLdisgner *dis = self.bigArr[self.phoneImage.tag]
    ;
    [self.Delate pushWithdisgnerId:dis.designerID];
//    NSLog(@"点/");
}




- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
